package com.fs.route;

import com.fs.filter.LogServiceFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@Slf4j
@RefreshScope
public class AlarmServerRouteConfig {

    public String uri="lb://px-basesystem-alarm";

    @Bean
    public RouteLocator LogServerRouteLocator(RouteLocatorBuilder builder) {
        if (uri == null || uri.equals("")) {
            log.info("日志服务路由为空");
            return null;
        } else {
            log.info("加载日志服务路由，数据库为：" + uri);
            return builder.routes().route(r -> r.path("/px-basesystem-alarm/**").
                    uri(uri).filters(new LogServiceFilter("/px-basesystem-alarm/(?<segment>.*)")).
                    id("px-basesystem-alarm")).build();
        }
    }
}

